<?php

class ErrorController extends Controller
{
    public function __construct()
    {
        parent::__construct('view', false);
    }

    public function view($ex = null)
    {
        if (!$ex) {
            $ex = App::getException();
            $ex || $ex = new Exception("Lỗi chưa xác định được!");
        }

        $this->ignoreMasterTemplate();

        $this->assign(array(
            'app_name' => Loader::getConfig('app', 'name'),
            'error_message' => $this->strongIt($ex->getMessage()),
            'error_detail' => print_r($ex, true),
            'refer' => App::getRefer()
        ));

    }

    public function strongIt($msg)
    {
        $msg = preg_replace('#(?<!\\\\)\[#', '<strong>[', $msg);
        $msg = preg_replace('#(?<!\\\\)\]#', '</strong>]', $msg);

        return $msg;
    }
}